package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Application;
import po.ComboboxItem;
import po.Result;
import service.ApplicationService;

import java.util.List;

@Controller
@RequestMapping("/application")
public class ApplicationController {

    @Autowired
    private ApplicationService applicationService;

    //返回应用信息界面视图
    @RequestMapping("/getApplicationInfoView")
    public String getApplicationInfoView() {
        return "application/applicationInfo";
    }

    //查询应用信息
    @RequestMapping("/findAllApplications")
    public @ResponseBody List<Application> findAllApplications() throws Exception {
        return applicationService.findAllApplications();
    }

    //为combobox查询应用信息
    @RequestMapping("/findAppForComb")
    public @ResponseBody List<ComboboxItem> findAppForComb() throws Exception {
        return applicationService.findAppForComb();
    }

    //返回添加应用界面视图
    @RequestMapping("/getAddApplicationView")
    public String getAddApplicationView() {
        return "application/addApplication";
    }

    //添加应用信息
    @RequestMapping("/addApplication")
    public @ResponseBody
    Result addApplication(Application application) {
        return applicationService.addApplication(application);
    }

    //删除应用信息
    @RequestMapping("/deleteApplication")
    public @ResponseBody
    Result deleteApplication(int id) {
        return applicationService.deleteApplicationById(id);
    }

    //返回修改应用信息界面视图
    @RequestMapping("/getEditApplicationView")
    public String getEditApplicationView() {
        return "application/editApplication";
    }

    //添加应用信息
    @RequestMapping("/updateApplication")
    public @ResponseBody
    Result updateApplication(Application application) {
        return applicationService.updateApplicationById(application.getId(), application);
    }
}
